import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;


/*
 * This class represents the threshold levels in the simulation
 */

public class Threshold {
	
	private double upperLimit;
	private double lowerLimit;
	private int level;
	private int hitCount=0;
	private int missCount=0;
	private ArrayList<HashMap<String,Double>> states = new ArrayList<HashMap<String,Double>>();
	
	//constructor
	public Threshold(int levelInput, double upperLimitInput,double lowerLimitInput){
		upperLimit=upperLimitInput;
		lowerLimit=lowerLimitInput;
		level=levelInput;
	}
	
	//upper limit retriever
	public double getUpperLimit(){
		return upperLimit;
	}
	
	//lower limit retriever
	public double getLowerLimit(){
		return lowerLimit;
	}
	
	//level retriever
	public double getLevel(){
		return level;
	}
	
	//hit count retriever
	public int getHitCount(){
		return hitCount;
	}
	
	//miss count retriever
	public int getMissCount(){
		return missCount;
	}
	
	//hit count incrementer
	public void addHitCount(){
		hitCount++;
	}
	
	//miss count incrementer
	public void addMissCount(){
		missCount++;
	}
	
	//hit ratio retriever
	public double getHitRatio(){
		return (double)hitCount/(double)missCount;
	}
	
	//overall hit ratio retriever
	public double getOverallHitRatio(){
		if (level==1)
			return getHitRatio();
		else
			return SplitSim.thresholds.get(level-1).getOverallHitRatio() * getHitRatio();
	}
	
	//adds the state of the system(upon threshold hit) to threshold level
	public void addState(HashMap<String,Double> stateInput){
		states.add(stateInput);
	}
	
	//retrieves the state of provided index within the threshold
	public HashMap<String,Double> getState(int index){
		//System.out.println("getting state# "+index+" out of "+states.size());
		return states.get(index);
	}
	
	//retrieves a random state of provided index within the threshold
	public HashMap<String,Double> getRandomState(){
		Random randomGen = new Random();
		return getState(randomGen.nextInt(states.size()));
	}
	
	//retrieves all the successful and stored states for the threshold
	public ArrayList<HashMap<String,Double>> getStates(){
		return states;
	}
}
